/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2020-10-20 17:48:29
 * @LastEditors: sueRimn
 * @LastEditTime: 2020-12-12 11:46:46
 */
import axios from 'axios'
import { Message } from 'element-ui'

// create an axios instance
const service = axios.create({
    timeout: 25000 // request timeout
})

// request interceptor
service.interceptors.request.use(
    config => {
        return config
    },
    error => {
    // do something with request error
        console.log(error) // for debug
        return Promise.reject(error)
    }
)

// response interceptor
service.interceptors.response.use(
    response => {
        if (response.data.code !== 200) {
            Message({
                message: response.data.message || response.data.msg,
                type: 'error',
                duration: 5 * 1000
            })
        }
        return Promise.resolve(response.data)
    },
    error => {
        console.log('err' + error) // for debug
        Message({
            message: error.message,
            type: 'error',
            duration: 5 * 1000
        })
        return Promise.reject(error)
    }
)

export default service
